import { createRouter, createWebHistory } from "vue-router";

const loadView = (view) => () => import(`@/views/${view}.vue`);

const routes = [
    {
        path: '/',
        redirect: '/login' // 默认跳转到登录页面
    },
    {
        path: '/login',
        component: loadView("Login")
    },
    {
        path: '/register',
        component: loadView("Register")
    },

    {
        path: "/main",
        name: "main",
        component: loadView("Main"),
        children: [
            {
                path: "/home",
                name: "home",
                component: loadView("Home")
            },
            {
                path: "/user",
                name: "user",
                component: loadView("User")
            },
            {
                path: "/mall",
                name: "mall",
                component: loadView("Mall")
            },
            {
                path: "/page1",
                name: "page1",
                component: loadView("Page1")
            },
            {
                path: "/page2",
                name: "page2",
                component: loadView("Page2")
            },
            {
                path: '/myUser',
                component: loadView("myUser")
            },
        ]
    },
    {
        path: '/:catchAll(.*)', // 捕获所有未匹配的路由
        name: '404',
        component: loadView('404')
    }
];

const router = createRouter({
    history: createWebHistory(),
    routes
});

export default router;